﻿//创建时间: 2010-12-15
//创建作者: 李 城
//功能说明: cms外部页面访问基类 信息点击量统计
//最后修改: 2010-12-15
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using TRPOP.CMS.Business;
using TRPOP.CMS.Model;
using System.Web;

using TRPOP.Config;
using TRPOP.Common;

namespace TRPOP.CMS.Web.ExtraBus
{
    /// <summary>
    /// 信息点击量统计
    /// </summary>
    public class Page_Load_InfoClickSubmit : BasePage
    {
        protected override void OnInit(EventArgs e)
        {
            string strInfoClickSubmit = SYSConfig.SystemVar_InfoClickSubmitURL.ToLower();
            string strDynamicPageName =
                (base.mCurrentUrl.ToLower().Contains(strInfoClickSubmit.ToLower().Trim())) ? "InfoClickSubmit" : "";
            if (strDynamicPageName == "InfoClickSubmit")
                SaveInfoClickCount();
            else
                Base_Config.NotFound(base.Page, "CMS后台配置的页面地址和访问的页面不一致(信息点击量统计)");
            //base.OnInit(e);
        }
        /// <summary>
        /// 信息统计
        /// </summary>
        public void SaveInfoClickCount()
        {
            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            ContentManage oContentManage = new ContentManage();
            ContentInfo oContentInfo = new ContentInfo();
            string ResJs = string.Empty;
            if (RequestHelper.RequestString("type") == "content")
            {
                ResJs = "{0}";
            }
            else
            {
                ResJs = "document.writeln(\"{0}\");";
            }
            //信息评论
            int intIndexid = RequestHelper.RequestInt("id");
            bool BlnNotshow = (RequestHelper.RequestString("show").Trim().ToLower() == "false");
            bool BlnNotSubmit = (RequestHelper.RequestString("submit").Trim().ToLower() == "false");
            if (intIndexid > 0)
            {
                oContentInfo = oContentManage.GetInfoById(intIndexid);
                if (oContentInfo != null)
                {
                    //记录点击
                    TRPOP.CMS.Plugin.ILogAccess.GetContentClickInstance().Save(oContentInfo.ContentId, false);
                    //信息点击量加1
                    if (BlnNotSubmit == false)
                    {
                        oContentInfo.Click = oContentInfo.Click + 1;
                        oContentManage.Save(oContentInfo, true);
                    }
                    if (BlnNotshow)
                        ResJs = string.Format(ResJs, "");
                    else
                        ResJs = string.Format(ResJs, oContentInfo.Click);
                }
            }
            Response.Write(string.Format(ResJs, 0));
        }
    }
}
